<!DOCTYPE html>
<html>
<head>
    <title>ads form</title>
    <#include "/header.html">
    <style>
        .layui-upload-img {
            max-height: 100px;
        }
    </style>
</head>
<body class="bg-white">

<div id="appMain">
    <form class="layui-form layuimini-form" action="" lay-filter="dataForm">
        <div class="layui-form-item">
            <label class="layui-form-label">网站名称</label>
            <div class="layui-input-block">
                <input type="text" id="name" name="name" placeholder="输入名称" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <!-- <div class="layui-form-item">
            <label class="layui-form-label">后台加密码</label>
            <div class="layui-input-block">
                <input type="text" id="key" name="key" placeholder="输入链接" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
      	<div class="layui-form-item">
            <label class="layui-form-label">后台模板</label>
            <div class="layui-input-block">
                <select name="target" lay-search>
                <option value="_blank">新标签页打开</option>
                <option value="_self">本窗口打开</option>
      			</select>
            </div>
        </div>
      	<div class="layui-form-item">
            <label class="layui-form-label">后台风格</label>
            <div class="layui-input-block">
                <select name="target" lay-search>
                <option value="_blank">新标签页打开</option>
                <option value="_self">本窗口打开</option>
      			</select>
            </div>
        </div> -->
        <div class="layui-form-item">
            <label class="layui-form-label">icp备案</label>
            <div class="layui-input-block">
                <input type="text" id="icp" name="name" placeholder="输入icp备案" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公安备案</label>
            <div class="layui-input-block">
                <input type="text" id="gw" name="name" placeholder="输入公安备案" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">站长邮箱</label>
            <div class="layui-input-block">
                <input type="text" id="em" name="name" placeholder="输入站长邮箱" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">统计代码</label>
            <div class="layui-input-block">
                <input type="text" id="tj" name="name" placeholder="输入统计代码" value="" class="layui-input" autocomplete="off">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-normal" id="commitBtn" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    layui.use(['form', 'laytpl', 'upload'], function () {
        var form = layui.form,
            laytpl = layui.laytpl,
            upload = layui.upload,
            $ = layui.$;

        var _parent = parent;
        /* laytpl(_parent.layui.jquery("#positionListTpl").html()).render(_parent.positionList, function(html){
            $("#positionListBox").html(html);
            form.render("select");
            if(_parent.formDataId > 0) {
                $.ajax({
                    type: "POST",
                    url: serverUrl('ads/info/' + _parent.formDataId),
                    success: function (result) {
                        if (result.code === 0) {
                            form.val('dataForm', result.info);
                            $('#uploadPreview').attr('src', result.info.image); //url
                        }
                    }
                });
            }
        });
 */

		 $(document).ready(function () {
		         $.ajax({
		             type: "POST",
		             url: serverUrl('hcoption/list'),
		             data: {},
		             dataType: "json",
		             success: function (result) {
							document.getElementById('name').value=result.name;
							document.getElementById('icp').value=result.icp;
							document.getElementById('gw').value=result.gw;
							document.getElementById('em').value=result.em;
							document.getElementById('tj').value=result.tj;
		             }
		         });
		 });
        var submitForm = function () {
            var params = form.val('dataForm');
			var stu="{\"site_name\":\"";
			stu=stu+document.getElementById('name').value+"\",\"site_seo_title\":\"";
			stu=stu+"\",\"site_seo_keywords\":\"";
			stu=stu+"\",\"site_seo_description\":\"";
			stu=stu+"\",\"site_icp\":\"";
			stu=stu+document.getElementById('icp').value+"\",\"site_gwa\":\"";
			stu=stu+document.getElementById('gw').value+"\",\"site_admin_email\":\"";
			stu=stu+document.getElementById('em').value+"\",\"site_analytics\":\""+document.getElementById('tj').value+"\"}";
			//河池市宜州区职业教育中心","site_seo_keywords":"","site_seo_description":""
			//iption":"","site_icp":"桂公网安备 45128102451351号","site_gwa":"","site_admin_email":"","site_analytics":""
            params['optionValue'] = stu;
			console.log(stu);
            submitFormData('hcoption/update', params);
        };

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#uploadBtn'
            ,url: serverUrl('oss/file/upload')
            ,auto: false
            ,choose: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#uploadPreview').attr('src', result); //base64
                });
            }
            ,done: function(res){
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                form.val('dataForm', {'img': res.url});
                submitForm();
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            submitForm();
            return false;
        });

    });
</script>
</body>
</html>